let num: number = 123;
let bol: boolean = true;
let str: string = '';

let ary: number[] = [1,2,3]
let ary2:Array<number|string> = [1,2,3,4,5,6,'']

//元组  规定好的数量和类型的数组
let  ary3:[string,number,number,boolean] = ['',1,3,true];

// 枚举类型
enum Gender{
  girl = 10,
  boy 
}
// Gender 一共四个属性
// 0  'girl'
// 1   'boy'
// girl  0
// boy   1
console.log(Gender.girl)
console.log(Gender[0])


let aaa:any = 123;
aaa = true;

function f1(name:string):string{
  return  '123'
}
f1('123')

function f2(name:string):any{
  return  '123'
}
f2('123')


function f3(name:string):void{
  // 在这个位置编写void 代表这个函数没有任何返回值
}
f3('123')



// 用type 声明一个函数类型
type fnType = (x:string,y:number) => string 
let f4:fnType = function(name:string,age:number=10){
  return name + age
}
f4('hello',10)

// 可选参数
let  f5 = function(name:string,age?:number):number{
  // age 不是比穿的
  return 123
}
f5('hello',10)

let f6 = function(...arr:Array<number|string>):void{

}
f6(1,2,'')

function f7(val:number):void
function f7(val:string):void
function f7(val:any):void {
  
}
// f7(true)

interface eat1{
  name:string;
  eatFn():void;
  [qqq:string]:any  // 代表还可能有很多不知道的什么属性
}
type eat={
  name:string;
  eatFn():void
}

let eatObj:eat1 = {
  name:'珠峰',
  eatFn(){},
  age:123,
  age1:123
}


interface type1 {
  name:string,
  age:number
}
interface type2 extends type1{
  sex:number
}

let obj2:type2 = {
  name:'',
  age:1,
  sex:1
}


function createAry(length:number,value:any):Array<any>{
  let res:any[] = [];
  for(let i = 0 ; i < length; i++){
    res[i] = 1
  }
  return res
}
console.log(createAry(3,''))

function createAry2<T>(length:number,value:T):Array<T>{
  let res:T[] = [];
  for(let i = 0 ; i < length; i++){
    res[i] = value
  }
  return res
}
createAry2<string>(3,'2')